{itemplate 'public/header'}
<link href="../addons/we7_wmall/plugin/superRedpacket/static/css/diy.web.css" rel="stylesheet" type="text/css"/>
<div class="clearfix">
	<div class="app-preview">
		<div class="app-header"></div>
		<div class="app-body">
			<div class="title">超级红包设置</div>
			<div class="main" id="app-preview"></div>
		</div>
		<div class="app-footer"></div>
	</div>
	<div class="app-editor form-horizontal" id="app-editor">
		<div class="editor-arrow"></div>
		<div class="inner"></div>
	</div>
</div>
{if $_GPC['id'] <= 0}
<div class="app-action">
	<div class="action">
		<nav class="btn btn-default btn-sm pull-left" id="gotop">返回顶部</nav>
		<nav class="btn btn-primary btn-sm btn-save">保存并开始发放</nav>
	</div>
</div>
{/if}
<script type="text/html" id="tpl-show-superRedpacket">
	<style>
		#sharemodal .banner{background-color: <(page.text.backgroundColor)>;}
		#sharemodal .container{background-color: <(page.text.backgroundColor)>;}
		#sharemodal .redpacket .circle-container .circle{background-color: <(page.text.backgroundColor)>;}
		#sharemodal .redpacket .redpacket-info{color: <(page.text.color)>;}
		#sharemodal .go-home a{color: <(page.button.color)>; background-color: <(page.button.backgroundColor)>;}
	</style>
	<div class="modal modal-no-buttons modal-in" id="sharemodal">
		<div class="banner">
			<img src="<(tomedia page.image)>" alt=""/>
		</div>
		<div class="container">
			<(each redpackets as redpacket index)>
				<div class="redpacket">
					<div class="redpacket-info row">
						<div class="col-75 text-left">
							<span class="redpacket-title"><(redpacket.name)></span>
						</div>
						<div class="col-25 price text-right">
							￥<span><(redpacket.discount)></span>
						</div>
					</div>
					<div class="circle-container">
						<span class="circle circle-left"></span>
						<span class="circle circle-right"></span>
					</div>
					<div class="redpacket-limit row">
						<div class="col-50 use-days-limit text-left">还有一天可使用</div>
						<div class="col-50 use-condition text-right">满<(redpacket.condition)>可用</div>
					</div>
				</div>
			<(/each)>
			<div class="go-home"><a href="javascript:;">进入首页</a></div>
		</div>
		<span class="icon icon-close js-close-modal" data-modal="#sharemodal"></span>
	</div>
</script>

<script type="text/html" id="tpl-edit-superRedpacket">
	<div class="alert alert-warning">添加之后不可修改也不可撤销,请谨慎操作</div>
	<div class="list-item">
		<div class="form-group">
			<div class="col-sm-2 control-label">红包名称</div>
			<div class="col-sm-10">
				<input type="text" class="form-control input-sm diy-bind" data-bind="name" placeholder="请输入名称" value="<(name)>" />
				<div class="help-block">注意：红包名称是便于后台查找。</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-2 control-label">顶部图片</div>
			<div class="col-sm-10">
				<div class="input-group">
					<input type="text" class="form-control input-sm diy-bind" placeholder="请选择图片或输入图片地址" value="<(page.image)>" data-bind-child="page" data-bind="image" id="pimg">
					<span class="input-group-addon btn btn-default js-selectImg" data-input="#pimg" data-element="#cimg">选择图片</span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-2 control-label">背景色</div>
			<div class="col-sm-5 color">
				<div class="input-group">
					<span class="input-group-addon">默认</span>
					<input class="form-control input-sm diy-bind color" type="color" data-bind-child="page" data-bind-parent="text" data-bind="backgroundColor" value="<(page.text.backgroundColor)>" />
					<span class="input-group-addon btn btn-default" onclick="$(this).prev().val('#b80404').trigger('propertychange')">清除</span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-2 control-label">优惠券名称及价格颜色</div>
			<div class="col-sm-5 color">
				<div class="input-group">
					<span class="input-group-addon">默认</span>
					<input class="form-control input-sm diy-bind color" type="color" data-bind-child="page" data-bind-parent="text" data-bind="color" value="<(page.text.color)>" />
					<span class="input-group-addon btn btn-default" onclick="$(this).prev().val('#fb584f').trigger('propertychange')">清除</span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-2 control-label">按钮背景色</div>
			<div class="col-sm-5 color">
				<div class="input-group">
					<span class="input-group-addon">默认</span>
					<input class="form-control input-sm diy-bind color" type="color" data-bind-child="page" data-bind-parent="button" data-bind="backgroundColor" value="<(page.button.backgroundColor)>" />
					<span class="input-group-addon btn btn-default" onclick="$(this).prev().val('#ffd161').trigger('propertychange')">清除</span>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-2 control-label">按钮背文字颜色</div>
			<div class="col-sm-5 color">
				<div class="input-group">
					<span class="input-group-addon">默认</span>
					<input class="form-control input-sm diy-bind color" type="color" data-bind-child="page" data-bind-parent="button" data-bind="color" value="<(page.button.color)>" />
					<span class="input-group-addon btn btn-default" onclick="$(this).prev().val('#333').trigger('propertychange')">清除</span>
				</div>
			</div>
		</div>
	</div>
	<div class="line"></div>
	<div class="list-item">
		<div class="form-items" data-min="1" data-max="2">
			<div class="inner">
				<(each redpackets as redpacket index)>
					<div class="item" data-id="<(index)>">
						<span class="btn-del del-item" title="删除"></span>
						<div class="item-body">
							<div class="form-group">
								<div class="col-sm-2 control-label">红包名称及金额</div>
								<div class="col-sm-10">
									<div class="input-group">
										<span class="input-group-addon">名称</span>
										<input class="form-control input-sm diy-bind" type="text" data-bind-child="redpackets" data-bind-parent="<(index)>" data-bind="name" value="<(redpacket.name)>">
										<span class="input-group-addon border-0-lr">金额</span>
										<input class="form-control input-sm diy-bind" type="text" data-bind-child="redpackets" data-bind-parent="<(index)>" data-bind="discount" value="<(redpacket.discount)>">
										<span class="input-group-addon">元</span>
									</div>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-2 control-label">使用条件</div>
								<div class="col-sm-10">
									<div class="input-group">
										<span class="input-group-addon">满多少元可用</span>
										<input class="form-control input-sm diy-bind" type="text" data-bind-child="redpackets" data-bind-parent="<(index)>" data-bind="condition" value="<(redpacket.condition)>">
										<span class="input-group-addon">元</span>
									</div>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-2 control-label">使用期限</div>
								<div class="col-sm-10">
									<div class="input-group">
										<span class="input-group-addon">领取后</span>
										<input class="form-control input-sm diy-bind" type="text" data-bind-child="redpackets" data-bind-parent="<(index)>" data-bind="grant_days_effect" value="<(redpacket.grant_days_effect)>">
										<span class="input-group-addon border-0-lr">天后生效</span>
										<span class="input-group-addon">有效期</span>
										<input class="form-control input-sm diy-bind border-0-l" type="text" data-bind-child="redpackets" data-bind-parent="<(index)>" data-bind="use_days_limit" value="<(redpacket.use_days_limit)>">
										<span class="input-group-addon">天</span>
									</div>
									<div class="help-block">
										如需红包发放后立即生效， 可设置为0
									</div>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-2 control-label">使用时间段</div>
								<div class="col-sm-10">
									<a href="javascript:;" class="btn btn-default btn-sm hour-add"><i class="fa fa-plus-circle"></i> 添加时间段</a>
								</div>
							</div>
							<div class="hour clockpicker">
								<(each redpacket.times as time timeid)>
									<div class="form-group">
										<div class="col-sm-2 control-label"></div>
										<div class="col-sm-9">
											<div class="input-group">
												<input type="text" readonly class="form-control input-sm diy-bind" data-bind-child="redpackets" data-bind-parent="<(index)>" data-bind="times" data-bind-category="<(timeid)>" data-bind-type="start_hour" value="<(time.start_hour)>">
												<span class="input-group-addon border-0-lr">至</span>
												<input type="text" readonly class="form-control input-sm diy-bind" data-bind-child="redpackets" data-bind-parent="<(index)>" data-bind="times" data-bind-category="<(timeid)>" data-bind-type="end_hour" value="<(time.end_hour)>">
											</div>
										</div>
										<div class="col-sm-1">
											<a href="javascript:;" class="btn-del hour-del" data-id="<(timeid)>"></a>
										</div>
									</div>
								<(/each)>
							</div>
							<div class="form-group">
								<div class="col-sm-2 control-label">使用分类</div>
								<div class="col-sm-10">
									<a href="javascript:;" class="btn btn-default btn-sm category-add"><i class="fa fa-plus-circle"></i> 选择分类</a>
								</div>
							</div>
							<div class="category-container">
								<div class="col-sm-2 control-label"></div>
								<div class="col-sm-10">
									<(each redpacket.categorys as category categoryid)>
										<div class="col-sm-3">
											<div class="category-item" id="category-<(categoryid)>">
												<a href="javascript:;" class="btn-del category-del" data-id="<(categoryid)>"></a>
												<img src="<(tomedia category.src)>" alt=""/>
												<div class="title js-selectCategory" data-id-input="#id-<(categoryid)>" data-title-input="#title-<(categoryid)>" data-src-input="#src-<(categoryid)>" data-element="#category-<(categoryid)>"><(category.title)></div>
												<input type="hidden" class="diy-bind" value="<(category.id)>" id="id-<(categoryid)>" data-bind-child="redpackets" data-bind-parent="<(index)>" data-bind="categorys" data-bind-category="<(categoryid)>" data-bind-type="id">
												<input type="hidden" class="diy-bind" value="<(category.title)>" id="title-<(categoryid)>" data-bind-child="redpackets" data-bind-parent="<(index)>" data-bind="categorys" data-bind-category="<(categoryid)>" data-bind-type="title">
												<input type="hidden" class="diy-bind" value="<(tomedia category.src)>" id="src-<(categoryid)>" data-bind-child="redpackets" data-bind-parent="<(index)>" data-bind="categorys" data-bind-category="<(categoryid)>" data-bind-type="src">
											</div>
										</div>
									<(/each)>
								</div>
							</div>
						</div>
					</div>
				<(/each)>
			</div>
			<div class="btn btn-default btn-block" id="addItem"><i class="icon icon-plus"></i> 添加一个</div>
		</div>
	</div>
	<div class="line"></div>
	<div class="list-item">
		<div class="form-group">
			<div class="col-sm-2 control-label">发放对象</div>
			<div class="col-sm-10">
				<div class="radio radio-inline">
					<input type="radio" value="0" name="type" class="diy-bind" data-bind-child="customer" data-bind="type" data-bind-init="true" id="type-0" <(if customer.type == 0)>checked<(/if)>>
					<label for="type-0">所有顾客</label>
				</div>
				<div class="radio radio-inline">
					<input type="radio" value="1" name="type" class="diy-bind" data-bind-child="customer" data-bind="type" data-bind-init="true" id="type-1" <(if customer.type == 1)>checked<(/if)>>
					<label for="type-1">指定顾客</label>
				</div>
				<div class="radio radio-inline">
					<input type="radio" value="2" name="type" class="diy-bind" data-bind-child="customer" data-bind="type" data-bind-init="true" id="type-2" <(if customer.type == 2)>checked<(/if)>>
					<label for="type-2">近30天成交顾客</label>
				</div>
				<div class="radio radio-inline" style="margin: 1px;">
					<input type="radio" value="3" name="type" class="diy-bind" data-bind-child="customer" data-bind="type" data-bind-init="true" id="type-3" <(if customer.type == 3)>checked<(/if)>>
					<label for="type-3">近30天未下单顾客</label>
				</div>
				<div class="radio radio-inline">
					<input type="radio" value="4" name="type" class="diy-bind" data-bind-child="customer" data-bind="type" data-bind-init="true" id="type-4" <(if customer.type == 4)>checked<(/if)>>
					<label for="type-4">近30天取消订单顾客</label>
				</div>
			</div>
		</div>
		<(if customer.type == 1)>
			<div class="form-group">
				<div class="uid-container">
					<textarea name="uid" class="form-control diy-bind" data-bind-child="customer" data-bind="uid" rows="8" placeholder="输入要指定的顾客的uid,多个uid之间用逗号隔开,例如: uid1,uid2,uid3"><(customer.uid)></textarea>
				</div>
			</div>
		<(/if)>
		<div class="form-group">
			<div class="col-sm-2 control-label">模板消息</div>
			<div class="col-sm-10">
				<div class="radio radio-inline">
					<input type="radio" value="1" name="template_notice" class="diy-bind" data-bind-child="customer" data-bind="template_notice" id="template-notice-1" <(if customer.template_notice == 1)>checked<(/if)>>
					<label for="template-notice-1">推送</label>
				</div>
				<div class="radio radio-inline">
					<input type="radio" value="2" name="template_notice" class="diy-bind" data-bind-child="customer" data-bind="template_notice" id="template-notice-2" <(if customer.template_notice == 2)>checked<(/if)>>
					<label for="template-notice-2">不推送</label>
				</div>
				<div class="help-block">如果发放的顾客很多, 不建议开启模板消息推送,因为这可能会被微信官方封杀公众号模板消息的权限。</div>
			</div>
		</div>
	</div>
</script>
<script language="javascript">
	var path = '../../plugin/superRedpacket/static/js/superRedpacket';
	irequire([path, 'tmodtpl'],function(superRedpacket, tmodtpl){
		superRedpacket.init({
			tmodtpl: tmodtpl,
			id: '{php echo intval($_GPC["id"])}',
			attachurl: "{$_W['attachurl']}",
			data: {if !empty($superRedpacket['data'])}{php echo json_encode($superRedpacket['data'])}{else}null{/if}
		});
	});
</script>
{itemplate 'public/footer'}